<template>
  <card-layout title="基金使用情况（万元）" class="chart">
    <template #extra>
      <el-icon class="extra-more" :size="22">
        <Menu />
      </el-icon>
    </template>
    <div class="card-container">
      <div class="stat-group">
        <div class="item">
          <div class="value">39<span class="suffix">/40</span> </div>
          <div class="label">已缴纳矿山</div>
        </div>
        <div class="item">
          <div class="value">3875.26</div>
          <div class="label">计提基金金额</div>
        </div>
        <div class="item">
          <div class="value">2167.16</div>
          <div class="label">提取基金金额</div>
        </div>
      </div>
      <div class="chart-container">
        <div style="width: 100%; height: 100%" ref="chartRef"></div>
      </div>
    </div>
  </card-layout>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import useChart from "@/hooks/useCharts.js";
const chartRef = ref(null);
let { chartInstance } = useChart(chartRef);

// 初始化图表
const initChart = () => {
  const option = {
    tooltip: {
      show: true,
    },
    legend: { show: true },
    grid: {
      show: false,
      top: 24,
      bottom: 0,
      right: 16,
      left: 12,
      containLabel: true,
    },
    xAxis: {
      type: 'value',
      boundaryGap: [0, 0.01],
      axisLine: {
        show: false,
      },
      splitLine: {
        show: false,
      }
    },
    yAxis: {
      type: 'category',
      data: ['计提基金', '提取基金'],
      splitLine: {
        show: false,
      }
    },
    series: [
      {
        name: '计划',
        type: 'bar',
        showBackground: true,
        data: [2321.56, 1847.63]
      },
      {
        name: '实际',
        type: 'bar',
        showBackground: true,
        data: [2271.84, 1975.9]
      },
    ]
  };
  chartInstance.value.setOption(option);
};

onMounted(() => {
  initChart();
});
</script>

<style lang="scss" scoped>
.chart {
  box-sizing: border-box;
  flex: 0.6;

  .card-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 8px;
  }

  .chart-container {
    flex: 1;
    width: 100%;
    position: relative;

    .chart-label {
      user-select: none;
      position: absolute;
      pointer-events: none;
      top: 0px;
      left: 0px;
      z-index: 1;
      height: 100%;
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;

      .percent {
        font-size: 26px;
        color: #fff;
      }

      .txt {
        color: #dedede;
        font-size: 14px;
      }
    }
  }
}
</style>
